from lib.pyse import Pyse
from faker import Faker
import time
fake=Faker(locale='zh_CN')
class BasicPage(object):
    def __init__(self):
        self.pyse = Pyse('chrome')
    def open(self):
        self.pyse.open('http://172.28.30.2:19090/creditplatformweb/login')
    def quit(self):
        self.pyse.quit()

class LoginPage(BasicPage):
   #查询系统的登录
   def sendUsername(self):
       css = 'css=>#username'
       self.pyse.type(css,'zjr')
   def sendPasswd(self):
        css = 'css=>#password'
        self.pyse.type(css,'111111-aA')
   def clickLogin(self):
        css = 'css=>#submit'
        self.pyse.click(css)
   def checkLogin(self,name):
       css = 'css=>a[href="creditLogout"]'
       return self.pyse.wait_and_save_exception(css,name)

class entInfoPage(LoginPage):
    def info(self):
        css = 'css=>a[id="30000000"]'
        self.pyse.click(css)
        css = 'css=>a[lay-href="/creditenterprisequeryweb/inquire/flow"]'
        self.pyse.click(css)
    def iframe(self):
        css = 'css=>iframe[src="/creditenterprisequeryweb/inquire/flow"]'
        self.pyse.switch_to_frame(css)
        css = 'css=>#inquireWrap'
        self.pyse.switch_to_frame(css)
    def enterpriseName(self):#企业名称
        css = 'css=>#enterpriseName'
        self.pyse.type(css,'企业名称a')
    def signCode(self):#中征码
        css = 'css=>#signCode'
        self.pyse.type(css,'1101021000126121')
    def uniformSocialCredCode(self):#统一社会信用代码
        css = 'css=>#uniformSocialCredCode'
        self.pyse.type(css,'91370684MA3N9PDP8X')
    def orgInstCode(self):#组织机构代码
        css = 'css=>#orgInstCode'
        self.pyse.type(css,'00000000-0')
    def getEntInfoBtn(self):#获取企业身份标识信息
        css = 'css=>#getEntInfoBtn'
        self.pyse.click(css)
    def assocbsnssData(self):#关联业务数据
        css = 'css=>input[name="assocbsnssData"]'
        self.pyse.type(css,'关联业务数据a')
    def note(self):#备注
        css = 'css=>input[name="note"]'
        self.pyse.type(css,'企业信用报告查询a')
    def queryFormat(self):#信用报告版本
        js = "document.getElementById('steps').style.display='block';"
        self.pyse.js(js)
        xpath = 'xpath=>//input[@id="form-validation-field-0"]'
        self.pyse.click(xpath)
        xpath = 'xpath=>//dd[@lay-value="00"]'
        self.pyse.click(xpath)
    def resultType(self):#信用报告封装类型
        css = 'css=>#form-validation-field-2'
        self.pyse.type(css,'html格式')
    def resetPage(self):#清空
        css = 'css=>#resetPage'
        self.pyse.click(css)
    def submitPage(self):#下一步
        css = 'css=>#submitPage'
        self.pyse.click(css)

class Page(entInfoPage):
    pass



if __name__=='__main__':
    page = Page()
    page.open()
    page.sendUsername()
    page.sendPasswd()
    page.clickLogin()
    page.checkLogin(LoginPage)
    page.info()
    page.iframe()
    page.enterpriseName()
